﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SSharp.Core.DataTypes;
using SSharp.Core.Evaluator;

namespace SSharp.Core.Builtins.Functions {
	public static class PrimitiveCons {
		public static readonly PrimitiveProcedure Cons = new PrimitiveProcedure("cons",
			args => {
				if (args.Length != 2) {
					throw new ApplicationError("cons: expects two arguments, given " + args.Length);
				}
				return new Cons(args[0], args[1]);
			});

		public static readonly PrimitiveProcedure Car = new PrimitiveProcedure("car",
			args => {
				if (args.Length != 1) {
					throw new ApplicationError("car: expents one argument, given " + args.Length);
				} else {
					Cons cons = args[0] as Cons;
					if (cons == null) {
						throw new ArgumentException("car: expects a cons, given " + args[0]);
					} else {
						return cons.car;
					}
				}
			});

		public static readonly PrimitiveProcedure Cdr = new PrimitiveProcedure("cdr",
			args => {
				if (args.Length != 1) {
					throw new ApplicationError("cdr: expents one argument, given " + args.Length);
				} else {
					Cons cons = args[0] as Cons;
					if (cons == null) {
						throw new ArgumentException("cdr: expects a cons, given " + args[0]);
					} else {
						return cons.cdr;
					}
				}
			});
	}
}
